package com.whw.fy.service.impl;

import com.whw.fy.entity.Message;
import com.whw.fy.mapper.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.whw.fy.entity.ParentComm;
import com.whw.fy.service.ParentCommService;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class ParentCommServiceImpl implements ParentCommService {

    @Resource
    private ParentCommMapper parentCommMapper;
    @Resource
    private StaffMapper staffMapper;
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private ParentMapper parentMapper;
    @Resource
    private RoomMapper roomMapper;

    @Override
    public Message deleteByPrimaryKey(Integer pCommId) {
        return parentCommMapper.deleteByPrimaryKey(pCommId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message insert(ParentComm record) {
        return parentCommMapper.insert(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message insertSelective(ParentComm record) {
        return parentCommMapper.insertSelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectByPrimaryKey(Integer pCommId) {
        ParentComm parentComm = parentCommMapper.selectByPrimaryKey(pCommId);
        HashMap hashMap = new HashMap();
        hashMap.put("parentComm", parentComm);
        hashMap.put("pstaffidDirectorName", staffMapper.selectByPrimaryKey(parentComm.getPStaffidDirector()).getStaffName());
        hashMap.put("pparentName", parentMapper.selectByPrimaryKey(parentComm.getPParentid()).getParentName());
        hashMap.put("pstaffName", staffMapper.selectByPrimaryKey(parentComm.getPStaffid()).getStaffName());
        hashMap.put("pstuName", studentMapper.selectByPrimaryKey(parentComm.getPStuid()).getStudentName());
        return Message.success(null).add(hashMap);
    }

    @Override
    public Message updateByPrimaryKeySelective(ParentComm record) {
        return parentCommMapper.updateByPrimaryKeySelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message updateByPrimaryKey(ParentComm record) {
        return parentCommMapper.updateByPrimaryKey(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectAll() {
        List<ParentComm> parentCommList = parentCommMapper.selectAll();
        List<Map> mapList = new LinkedList<>();
        for (ParentComm parentComm : parentCommList) {
            HashMap hashMap = new HashMap();
            hashMap.put("parentComm", parentComm);
            hashMap.put("pstaffidDirectorName", staffMapper.selectByPrimaryKey(parentComm.getPStaffidDirector()).getStaffName());
            hashMap.put("pparentName", parentMapper.selectByPrimaryKey(parentComm.getPParentid()).getParentName());
            hashMap.put("pstaffName", staffMapper.selectByPrimaryKey(parentComm.getPStaffid()).getStaffName());
            hashMap.put("pstuName", studentMapper.selectByPrimaryKey(parentComm.getPStuid()).getStudentName());
            hashMap.put("pattendingDoctorName", staffMapper.selectByPrimaryKey(parentComm.getPAttendingdoctorId()).getStaffName());
            hashMap.put("pmeetingPlaceName",roomMapper.selectByPrimaryKey(parentComm.getPMeetingplaceId()).getRoomLoc());
            mapList.add(hashMap);
        }

        return Message.success(null).add(mapList);
    }

    @Override
    public int batchInsert(List<ParentComm> list) {
        return parentCommMapper.batchInsert(list);
    }
}


